package com.caifu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caifu.bean.PageDo;
import com.caifu.bean.Result;
import com.caifu.bean.ResultUtil;
import com.caifu.pojo.YsLabel;
import com.caifu.service.LabelService;
import com.caifu.util.Util;
import com.caifu.vo.label.SaveMsLabelVO;
import com.caifu.vo.label.UpdateMsLabelVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName : LabelController
 *
 * @author :  szt
 * @description ：
 * @date : 2021-03-08 16:10
 */
@Controller
@RequestMapping("/label")
public class LabelController {

    @Resource
    private LabelService labelService;

    /**
     * 标签管理
     * 192.168.1.180:8080/WLstoreArchivesManageSystem/label/jumpLabel
     * 2021/3/8
     * codeBy szt
     */
    @RequestMapping(value = "jumpLabel")
    public ModelAndView jumpLabel() {
        ModelAndView modelAndView = new ModelAndView();
        try {
            modelAndView.addObject("labelType", labelService.getLabelType().getData());
            modelAndView.setViewName("/shopMember/label/list");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return modelAndView;
    }

    /**
     * 标签 分页
     *
     * @param labelCode 主labelCode
     * @return Result
     */
    @GetMapping(value = "getLabelListByLabelCodePagination")
    @ResponseBody
    public Result<Object> getLabelListByLabelCodePagination(String labelCode, Integer currentPage, Integer pageSize) {
        try {
            Result<Object> result = labelService.getLabelListByLabelCodePagination(labelCode, currentPage, pageSize);
            result.setCode(0);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error();
        }
    }

    /**
     * 保存标签
     *
     * @param saveMsLabelVO vo
     * @return Result
     */
    @RequestMapping(value = "saveLabel")
    @ResponseBody
    public Result<Object> saveLabel(SaveMsLabelVO saveMsLabelVO) {
        try {
            return labelService.addLabel(saveMsLabelVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error();
        }
    }

    /**
     * 修改标签
     */
    @RequestMapping(value = "updateLabel")
    @ResponseBody
    public Result<Object> updateLabel(UpdateMsLabelVO updateMsLabelVO) {
        try {
            return labelService.updateLabel(updateMsLabelVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error();
        }
    }

    /**
     * 删除 标签
     */
    @RequestMapping(value = "deleteLabel", method = RequestMethod.POST)
    @ResponseBody
    public Result<Object> deleteLabel(String labelCode) {
        try {
            return labelService.deleteLabel(labelCode);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error();
        }
    }

    /**
     * 关闭|启动 标签
     */
    @RequestMapping(value = "updateLabelState", method = RequestMethod.POST)
    @ResponseBody
    public Result<Object> updateLabelState(String labelCode, String state) {
        try {
            return labelService.updateLabelState(labelCode,state);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error();
        }
    }



}
